<template>
	<div class="login-box">
		<div class="login">
		<h1 class="title">保尔酒庄</h1>
		<div class="inp put">
			<span>账号:</span><el-input v-model="user" placeholder="请输入用户名" class="inpu"></el-input>
		</div>
		<div class="inp pua">
			<span>密码:</span><el-input placeholder="请输入密码" v-model="pwd" show-password class="inpu" @keyup.enter.native="login"></el-input>

		</div>
		<button @click="login" class="dl">登录</button>
		</div>
	
	</div>
</template>

<script>

	export default{
		data(){
			return{
				user:"",
				pwd:"",
				baseUrl:require("../assets/baseUrl.js").baseUrl
			}
		},
		methods:{
			changeLoginaa(id){
				this.$http.post(this.baseUrl+"admin/changeLog",{
					adminId:id,
					logStatus:0
				}).then(res=>{
					/* console.log(res) */
				})
			},
			login(){
				// http://localhost:8081/admin/checkStore
				//sessionStorage.setItem("username","张三");
				if(this.user===""||this.pwd===""){
					this.$message({
						message:"用户名和密码不能为空",
						type:"error"
					})
				}else{
					this.$http.post(this.baseUrl+"admin/checkStore",{
						adminAccount:this.user,
						adminPassword:this.pwd
					}).then(res=>{
						// console.log(res) 
						if(res.data.code==200){
							if(!sessionStorage.getItem("adminId")){
								this.$message({
								message:"登陆成功",
								type:"success"
								
							})
							}
							this.changeLoginaa(res.data.data[0].adminId)
							sessionStorage.setItem("adminName",res.data.data[0].adminName)
							sessionStorage.setItem("adminId",res.data.data[0].adminId)
							sessionStorage.setItem("adminAccount",res.data.data[0].adminAccount)
							sessionStorage.setItem("adminPhone",res.data.data[0].adminPhone)
							sessionStorage.setItem("adminRole",res.data.data[0].adminRole)
							sessionStorage.setItem("iserIcon",res.data.data[0].iserIcon)
							sessionStorage.setItem("logStatus",res.data.data[0].logStatus)
							this.$router.replace('/homepage')
						}else{
							this.$message({
								message:res.data.msg,
								type:"error"
							})
							this.user=""
							this.pwd=""
						}
						
					})				
				}				
			},
			//自动登录
			zidoong(){
				if(sessionStorage.getItem("adminAccount")){
					this.$router.push("/homepage")
				}
			}
			
		},
		mounted() {
		/* 	this.changeLogin() */
		this.zidoong()
			// this.$http.post(this.baseUrl+"admin/changeLogin",{
			// 	adminId:"2",
			// 	logStatus:"0"
			// }).then(res=>{
			// 	console.log(res)
			// })
			
		}	
	}
</script>
<style lang="less">
*{
	margin: 0;
	padding: 0;
}
.login-box{
	width: 100vw;
	height: 100vh;
	background: url("../assets/login.png");
  	background-size: 100% 100%;
  	display: flex;
  	justify-content: center;
  	align-items: center;
	  .login{
	width: 600px;
	height: 430px;
	border: 1px solid #000;
	border-radius: 10px;
	position: relative;
	background: #fff;
	opacity: 0.7;
	position: relative;
}
.inp{
	display: flex;
	align-items: center;
	justify-content: center;
}

.inp span{
	width: 65px;
	height: 40px;
	text-align: center;
	line-height: 40px;
	color: #000;
	font-weight: 700;
}
.inp .el-input{
	width: 300px;
	border:2px solid #000;
	border-radius: 5px;
	background: none;
}
.put{
	position: absolute;
	bottom: 227px;
	left: 125px;
}
.pua{
	position: absolute;
	bottom: 162px;
	left: 125px;
}
.dl{
	width: 150px;
	height: 50px;
	font-size: 24px;
	font-weight: 700;
	color: #fefefe;
	background: #652013;
	border-radius:25px;
	position: absolute;
	bottom: 52px;
	left: 38%;
}
.title{
	position: absolute;
	top: 70px;
	left: 38%;
}
}

</style>